package main

import (
	"fmt"
)

func GetData(s string) (int, int) {
	fmt.Println("params:", s)
	return 100, 200
}

func modifyfromPoint(num int) {
	// 未使用指针
	num = 1000
	fmt.Println("the value in func:", num)
}

func NewmodifyfromPoint(num *int) {
	// 已使用指针
	*num = 1000
	fmt.Println("the value in func:", num)
}

// 全局变量
var global int = 3

func main(){
	fmt.Println("hello,可爱的帅哥美女们")
	/*   变量
	var a int
	var b string
	var c float32
	var d func() bool
	fmt.Println(a, b, c, d)
	//var (
	//	aa int
	//	bb string
	//)
	var attack = 40
	fmt.Println(attack)
	fmt.Printf("%d\n", attack)
	var a1 int = 100
	var b1 int =200
	b1 , a1 = a1, b1
	fmt.Println("getData input:", a1, b1)
	//a2 := 300
	f1, _ := GetData("gbe")
	fmt.Println(f1)
	//_ := 2  这是错误的用法
	//fmt.Println(f1)
	// var floatStr float32
	floatStr:= 3.145
	fmt.Println(floatStr)
	fmt.Printf("%T\n" , floatStr)
	fmt.Printf("%.2f\n" , floatStr)

	var listA []int
	fmt.Println(listA)
	var listB = []int{1,2,3}
	fmt.Println(listB)
	fmt.Println(len(listB))
	fmt.Println(listB[0])
	// &&: 与
	// || : 或
	 */

	/*
	// var str1 string
	str1 := "hello"
	str2 :="你好"
	fmt.Println("\n", len(str1))
	fmt.Println("\t",utf8.RuneCountInString(str2))
	str3 := `\tGo大法好`
	fmt.Println(str3)
	// 只要是字母和数字 都是unint(byte)
	//var aa byte = 'a'
	//fmt.Printf("%T", aa)
	//var bb rune = '你'
	//fmt.Printf("%T", bb)
	str1 := "hello"
	str2 :="你好,可爱的帅哥美女们"
	fmt.Printf("%c\n", str1[0])
	fmt.Printf("%\n", str2[0])   // 直接用索引对rune类型是无效的
	fmt.Println(string([]rune(str2)[0:5]))
	for i :=0; i<len(str1) ; i++ {
		fmt.Printf("ascii: %c %d\n", str1[i], str1[i])
	}

	for _, s := range str1 {
		fmt.Printf("unicode: %c %d\n", s, s)
	}
       // 查找字符串
	tracer := "死神来了,死神bye bye"
	comma := strings.Index(tracer, ",")
	fmt.Println("comma" , comma)
	pos := strings.Index(tracer[comma:], "死神")
	fmt.Println(comma, pos, tracer[comma+pos:])

	// 修改字符串
		readyStr := "Heros never die"
		angleBytes := []byte(readyStr)
		for i:=5 ; i<=10 ; i++ {
			angleBytes[i] = ' '
		}
		fmt.Println("str after modify :", string(angleBytes))
	// 高性能版本的字符串拼接
	str1 := "美女"
	str2 := "性感"
	var stringBuilder bytes.Buffer
	stringBuilder.WriteString(str1)
	stringBuilder.WriteString(str2)
	fmt.Println(stringBuilder.String())
	//s1 := stringBuilder.String()
	// s2 := fmt.Sprintln(stringBuilder.String())

	// str to int
		str1 := "1"
		intValue, _ := strconv.Atoi(str1)
		fmt.Printf("%T,%d:", intValue, intValue)

	// int to str
		intValue := 1
		strValue := strconv.Itoa(intValue)
		fmt.Printf("%T,%s:", strValue, strValue)

	     // str > float
		string1 := "3.14159265"
		f, _ := strconv.ParseFloat(string1, 32)
		fmt.Printf("%T,%f:", f, f)

	    // str > slice
		s:= "你,好"
		fmt.Println(strings.Split(s, ","))
		// slice > str
		list_ := []string{"aaa", "bbb"}
		fmt.Println(strings.Join(list_, ","))
		// 1. str := "语言Python大法好"
		// 2. str2 := "语言Golang大法好,语言Golang大法好,语言Golang大法好,语言Golang大法好,语言Golang大法好,语言Golang大法好,Golang"

		// 常量
		const constValue = "aaa"
		const (
			left  = iota
			top
			right
			bttom
		)
		fmt.Println(left, top, right, bttom)

		// 指针入门
		var room int =10
		var ptr =&room
		fmt.Printf("指针地址：%p, %T\n", ptr, ptr)
		fmt.Println("指针地址代表的值", *ptr)
		// 指针修改
		intValue :=2
		modifyfromPoint(intValue)
		//fmt.Println("the value outside func: ", intValue)
		NewmodifyfromPoint(&intValue)
		fmt.Println("the value outside func: ", intValue)
	 */


























}